<?php

namespace addons\shopro\command;

use addons\shopro\controller\Address;
use addons\shopro\services\CategoryService;
use think\console\Command;
use think\console\Input;
use think\console\input\Argument;
use think\console\Output;

class Category extends Command
{

    /**
     * @return void
     * @Author ycr <E-mail:yuncran@126.com>
     */
    protected function configure()
    {
        $this->setName('cate:category')
            ->addArgument('action', Argument::OPTIONAL, "action start [d]|stop|restart|status")
            ->addArgument('type', Argument::OPTIONAL, "d -d")
            ->setHelp('此命令是用来启动 预载 商城分类服务端进程')
            ->setDescription('积分商城-分类预载 使用方法 php think cate:category');
    }

    /**
     * @param Input $input
     * @param Output $output
     * @return array|bool|int|mixed|\PDOStatement|string|\think\Model|null
     * @Author ycr <E-mail:yuncran@126.com>
     */
    protected function execute(Input $input, Output $output)
    {
        global $argv;
        $action = trim($input->getArgument('action'));
        $type = trim($input->getArgument('type')) ? '-d' : '';

        $argv[0] = 'cate:category';
        $argv[1] = $action;
        $argv[2] = $type ? '-d' : '';
        $this->start();
    }

    protected function start()
    {
        /** 省市县乡街道 */
        (new Address())->area();
        /** 商品分类 */
        (new CategoryService())->getCategory(0);

        return true;
    }

}